package com.li.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.li.bean.User;
import com.li.dao.UserDao;
import com.li.daoImpl.UserDaoImpl;

public class RegisterServlet extends HttpServlet {


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		UserDao ud = new UserDaoImpl();
		User user = new User();
		String usern = request.getParameter("username");
		String userp = request.getParameter("userpwd");
		String email = request.getParameter("email");
		System.out.println(usern);
		user.setUsern(usern);
		user.setUserp(userp);
		user.setEmail(email);
		ud.userAdd(user);
		System.out.println(usern);
		
		List<User> list = ud.getArticle(user.getUsern());
		for (int i = 0; i < list.size(); i++) {
			System.out.println(list.get(i).getUsern());
		}
		request.setAttribute("list", list);
		request.getRequestDispatcher("./user.jsp").forward(request, response);

	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doGet(request, response);
	}

}
